﻿using System;
using Gp.Scripts.Core.Command;
using QFramework;
using UnityEngine;

namespace Gp.Scripts.Core
{
    /// <summary>
    /// 在战斗初始化前发送
    /// </summary>
    public class Event_BattleInit { }

    /// <summary>
    /// 在战斗初始化完成后发送
    /// </summary>
    public class Event_BattleStart { }


    public class Event_BattleEnd
    {
        public BattleSettleRoot EndLevel;

        public Event_BattleEnd(BattleSettleRoot endLevel)
        {
            EndLevel = endLevel;
        }
    }


    public class BattleStartCommand : AbstractCommand
    {
        protected override void OnExecute()
        {
            if (Global.Get<BattleSystem>().Level != null) return;
            // 切换输入层级
            Global.Get<InputLayerSystem>().SwitchToUILayer(typeof(BattleSettleRoot));

            // 获得玩家预设
            // var config = this.GetModel<RulesModel>();

            // 开始战斗

            // 播放战斗音乐
            Global.Get<MusicManageSystem>().PlayBattleMusic();
        }
    }


    public class BattleEndCommand : AbstractCommand
    {
        private readonly BattleSettleRoot _settle;

        public BattleEndCommand(BattleSettleRoot settle)
        {
            _settle = settle;
        }


        protected override void OnExecute()
        {
            // 切换输入层级
            Global.Get<InputLayerSystem>().SwitchToBase(typeof(BattleSettleRoot));


            // 将摄像机调回角色视角
            this.SendCommand(new ChangeCameraMotorCommand());

            SceneScriptArchitecture.Interface.SendEvent(new Event_BattleEnd(_settle));
            try
            {
                this.SendEvent(new Event_BattleEnd(_settle));
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
                Debug.LogError(e.StackTrace);
            }


            // // 恢复光标
            // Global.Get<CursorManager>().Recover();

            // 结束战斗音乐
            Global.Get<MusicManageSystem>().EndBattleMusic();
        }
    }
}